<%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*,com.book.model.*,com.book.formbean.*"  pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>welcome come to bookzang</title>
<%
BookPage bookPage=(BookPage)request.getAttribute("bookPage");
BookForm bookForm=(BookForm)request.getAttribute("bookForm");
Type type=(Type)request.getAttribute("type");

List<Book> books=bookPage.getBooks();
int bookCount=bookPage.getBookCount();
int pageNo=bookForm.getPageNo();
int pageSize=bookForm.getPageSize();
int booksSize=books.size();
int totalPageSize=0;
if(bookCount%pageSize==0){totalPageSize=bookCount/pageSize;}else{totalPageSize=bookCount/pageSize+1;}
%>
<script language="javascript">

function getSelectedValue(name)
{
var obj=document.getElementById(name);
return obj.value;
}

function search()
{
	if(checkConditions())
	{
		document.getElementById("bookForm").submit();
	}
}


function checkConditions()
{
	return true;
}

</script>
<link href="resources/style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form:form  method="get" name="bookForm" id="bookForm" action="login.do"  commandName="bookForm">

		<tr>
			<td align="center" height="60" valign="middle">
				<spring:message code="book.form.title.lable"/>:&nbsp; 
			<input type="text" id="title" name="title" size="12" value="${bookForm.title}" />&nbsp;&nbsp; 
			<spring:message code="book.form.author.lable"/>:&nbsp; 
			<input type="text" id="author" name="author" size="12" value="${bookForm.author}" />&nbsp;&nbsp; 

				<%=type.getBigtype1()%>:&nbsp;
				<form:select path="type1"  multiple="false"  cssStyle="height:20px" >
					<form:option value="ALL" label="ALL"/>
					<form:options items="${type.type1s}"  itemValue="id" itemLabel="name"  />
				</form:select>
				
					<%=type.getBigtype2()%>:&nbsp;
				<form:select path="type2"  multiple="false"  cssStyle="height:20px" >
					<form:option value="ALL" label="ALL"/>
					<form:options items="${type.type2s}"  itemValue="id" itemLabel="name"  />
				</form:select>
					
					<%=type.getBigtype3()%>:&nbsp;
				<form:select path="type3"  multiple="false"  cssStyle="height:20px" >
					<form:option value="ALL" label="ALL"/>
					<form:options items="${type.type3s}" itemValue="id" itemLabel="name" />
				</form:select>
				
				<spring:message code="table.book.page.pagesize"/>：&nbsp;<input type="text" id="pageSize" name="pageSize" size="3" value="${bookForm.pageSize}" /> &nbsp;&nbsp;

				<spring:message code="table.book.page.pagenumber"/>：&nbsp;<input type="text" id="pageNo" name="pageNo" size="3" value="${bookForm.pageNo}" /> &nbsp;&nbsp;
				
				<input type="button"  value=<spring:message code="book.form.search.lable"/> onclick="search()"/>&nbsp;&nbsp;		  </td>
		</tr>	
					
</form:form>
</table>

<table border="0" width="100%">
	<tr>
		<td width="70%" align="right" class="headerBc" style="padding-right:100px;">&nbsp;&nbsp;<a href="addPageInit.do" ><spring:message code="html.link.add"/></a></td>
		<td class="headerBc" width="30%"><div align="right">Search&nbsp;Result:&nbsp;<spring:message code="table.book.page.totalcount"/>：<%=bookCount%>&nbsp;<%=pageNo%>/<%=totalPageSize%>
		
		</div></td>
	</tr>
</table>



<table width="800" border="1" align="center" cellpadding="1" cellspacing="0" style="margin-top:10px;">
  <tr>

    <td align="center">&nbsp;<spring:message code="book.title"/></td>
	<td align="center">&nbsp;<spring:message code="book.author"/></td>
    <td align="center">&nbsp;<spring:message code="book.type"/></td>
    <td align="center">&nbsp;<spring:message code="book.time"/></td>
    <td align="center">&nbsp;</td>
  </tr>
  <%
for(int i=0;i<booksSize;i++)
{
Book book=books.get(i);
%>
	
	 <tr>

    <td align="center">&nbsp;<%=book.getTitle()%></td>
	    <td align="center">&nbsp;<%=book.getAuthor()%></td>
    <td align="center">&nbsp;<%=book.getType()%></td>
    <td align="center">&nbsp;<%=book.getDateToString()%></td>
    <td align="center">&nbsp;<a href="del.do?id=<%=book.getId()%>&path=<%=java.net.URLEncoder.encode(book.getPath(), "utf-8")%>"><spring:message code="book.form.delete.lable"/></a> </td>
  </tr>
	<%
	}
%>
 
</table>


<table width="500" height="30" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><%if(pageNo==1){%><b><spring:message code="table.book.page.prev"/></b><%}else{%><a href="login.do?pageNo=<%=pageNo-1%>&title=<%=bookForm.getTitle()%>&type1=<%=bookForm.getType1()%>&type2=<%=bookForm.getType2()%>&type3=<%=bookForm.getType3()%>&author=<%=bookForm.getAuthor()%>" ><b><spring:message code="table.book.page.prev"/></b></a><%}%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<%if(pageNo==totalPageSize){%><b><spring:message code="table.book.page.next"/></b><%}else{%><a href="login.do?pageNo=<%=pageNo+1%>&title=<%=bookForm.getTitle()%>&type1=<%=bookForm.getType1()%>&type2=<%=bookForm.getType2()%>&type3=<%=bookForm.getType3()%>&author=<%=bookForm.getAuthor()%>" ><b><spring:message code="table.book.page.next"/></b></a><%}%></td>
  </tr>
</table>
</body>
</html>
